/****************************************************
	文件：ResContext.cs
	作者：HuskyT
	邮箱：1005240602@qq.com
	日期：2021/1/9 15:40:9
	功能：资源上下文
*****************************************************/

using System;
using UnityEngine;
using HTFW.Consts;
using HTFW.Res;
using HTFW.Utility;

namespace HTFW.Core
{
    public class ResContext : IContext
    {
        RPrefab mRPrefab; //GameObject 加载器
        RObject mRObject; //不需要实例化的 Unity Object 加载器

        /// <summary>
        /// GameObject 加载器
        /// </summary>
        public RPrefab RPrefab => mRPrefab;

        /// <summary>
        /// 不需要实例化的 Unity Object 加载器
        /// </summary>
        public RObject RObject => mRObject;

        public ContextType ContextType { get; set; }
        public ContextScope ContextScope { get; set; }
        public Action<IContext> OnInit { get; set; }
        public Action<IContext> OnDispose { get; set; }


        public ResContext()
        {
            mRPrefab = new RPrefab(this);
            mRObject = new RObject(this);
        }

        public void Init(params object[] args)
        {
            OnInit?.Invoke(this);
        }

        public void Dispose()
        {
            OnDispose?.Invoke(this);

            OnInit = null;
            OnDispose = null;
        }
    }
}